package com.dm.cloud.core.exception;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@NoArgsConstructor
@Data
public class CustomException extends BaseException{
    private Throwable throwable;
    public CustomException(String msg,int code,Throwable err){
        super(code,msg);
        this.throwable= err;
    }
    public CustomException(String msg){
        super(500,msg);
        this.throwable= null;
    }
    public CustomException(String msg,Throwable err){
        super(500,msg);
        this.throwable= err;
    }
    public String getMsg() {
        if(throwable!=null){
            return super.getMsg()+"\n"+throwable.getMessage();
        }else{
            return super.getMsg();
        }
    }

    public static CustomException serverErr(String msg){
        return new CustomException(msg,500,null);
    }

    public static CustomException serverErr(){
        return new CustomException("服务错误", 500,null);
    }

    public static CustomException serverErr(String msg,Throwable err){
        return new CustomException(msg,500,err);
    }

    public static CustomException serverErr(Throwable err){
        return new CustomException(err.getMessage(), 500,err);
    }

}
